<?php
namespace app\admin\controller;
class Project extends Common {

	/*
	*	构造函数
	*/
	function __construct(){
		parent::__construct();
	}

	public function index(){

		$pageParam    = ['query' =>[]];
		$where = [];

		$item_name = input('item_name');
		if($item_name != '')
		{
			$where['xp.item_name'] = array('like','%'.$item_name.'%');
			$pageParam['query']['item_name'] = $item_name;
		}

		$certificate_no = input('certificate_no');
		if($certificate_no != '')
		{
			$where['xp.certificate_no'] = array('like','%'.$certificate_no.'%');
			$pageParam['query']['certificate_no'] = $certificate_no;
		}

		$type = input('type');
		if($type != '0' && !empty($type))
		{
			$where['xp.type'] = $type;
			$pageParam['query']['type'] = $type;
		}

		$name = input('name');
		//var_dump($name);
		if($name != ''){
			$where['xc.name'] = array('like','%'.$name.'%');
			$pageParam['query']['name'] = $name;
		}

		//时间批次
		$time_batch = input('time_batch');
		if($time_batch != ''){
			$where['xp.time_batch'] = array('like','%'.$time_batch.'%');
			$pageParam['query']['time_batch'] = $time_batch;
		}


		//查询分类名
		$project_type = db('project_type')->select();

		$project_result = db('xls_project')->where($where)->alias('xp')->join('xls_company xc','xc.id = xp.company_id')->join('project_type pt','pt.id = xp.type')->field('xp.*,xc.name,pt.type_name')->order('xp.id desc')->paginate(10, false, $pageParam);

		$page = $project_result->render();
		$this->assign('project_result',$project_result);
		$this->assign('project_type',$project_type);
		$this->assign('name',$name);
		$this->assign('type',$type);
		$this->assign('certificate_no',$certificate_no);
		$this->assign('item_name',$item_name);
		$this->assign('time_batch',$time_batch);
		$this->assign('page',$page);
		return 	$this->fetch();
	}

	public function delete()
	{
		$id = input("id");
		if(!$id) $this->error('参数有误');
		$da=db('xls_project')->where("id='$id'")->find();
		if(!$da) $this->error('数据不存在');
		$res=db('xls_project')->where("id='$id'")->delete();
		if(!$res) $this->error('删除失败');
		$this->success("删除成功!",url('project/index'));
	}
}